''' <summary>
''' This is a game component that implements IUpdateable.
''' </summary>
Public Class Claw
    Inherits Microsoft.Xna.Framework.DrawableGameComponent
    Private mModel As Model

    Private mRowCount As Integer = 30
    Private mModelSet As Boolean = False
    Private mLeft As Boolean
    Private mRow As Integer
    Private mGameRun As GameRun

    Public Sub New(ByVal game As Game, ByVal GameRun As GameRun, ByVal Left As Boolean, ByVal Row As Integer)
        MyBase.New(game)
        mGameRun = GameRun
        mLeft = Left
        mRow = Row
    End Sub

    Public Overrides Sub Initialize()
        MyBase.Initialize()
    End Sub

    Protected Overrides Sub LoadContent()
        mModel = Game.Content.Load(Of Model)("bigbar")
        MyBase.LoadContent()
    End Sub

    ' Resets the objects World matracies to be what has been specified
    Private Sub ResetModel()
        Dim myMatrix As Matrix
        Dim UnitSize As Single = mGameRun.UnitSize
        Dim Scale As Vector3 = New Vector3(CSng(UnitSize * 0.2), CSng(UnitSize * 0.2), CSng(UnitSize * 0.2))
        Dim Rotate As Vector3 = New Vector3(0, 90, 0)
        Dim Location As Vector3 = New Vector3(0, -UnitSize * 5, mRow * UnitSize)

        myMatrix = Matrix.Identity * Matrix.CreateScale(Scale) * Matrix.CreateRotationX(Rotate.X) * Matrix.CreateRotationY(Rotate.Y) * Matrix.CreateRotationZ(Rotate.Z) * Matrix.CreateTranslation(Location)
        For Each ModelMesh As ModelMesh In mModel.Meshes
            Dim transforms As Matrix() = New Matrix(mModel.Bones.Count) {}
            mModel.CopyAbsoluteBoneTransformsTo(transforms)
            For Each effect As BasicEffect In ModelMesh.Effects
                effect.View = mGameRun.Effect.View
                effect.Projection = mGameRun.Effect.Projection
                effect.World = myMatrix
                effect.EnableDefaultLighting()
            Next effect
        Next
    End Sub

    Public Overrides Sub Draw(gameTime As Microsoft.Xna.Framework.GameTime)
        If (Not mModelSet) Then
            mModelSet = True
            For Each ModelMesh As ModelMesh In mModel.Meshes
                For Each effect As BasicEffect In ModelMesh.Effects
                    With mGameRun
                        effect.FogEnabled = .Effect.FogEnabled
                        effect.FogColor = .Effect.FogColor
                        effect.FogStart = .Effect.FogStart
                        effect.FogEnd = .Effect.FogEnd
                    End With
                Next
            Next
        End If
        ResetModel()
        'End If
        If (mRow * mGameRun.UnitSize < mGameRun.CameraPosition.Z - mGameRun.UnitSize * 2) Then
            mRow += mRowCount
            ResetModel()
        End If
        For Each Model As ModelMesh In mModel.Meshes
            Model.Draw()
        Next
        MyBase.Draw(gameTime)
    End Sub

    Public Overrides Sub Update(ByVal gameTime As GameTime)
        MyBase.Update(gameTime)
    End Sub

End Class
